from pydantic import BaseModel, Field
from typing import Optional, List


class UserCreate(BaseModel):
    username: str = Field(..., description="用户名")
    password: str = Field(..., description="密码（明文，服务层会进行哈希）")
    name: Optional[str] = Field(None, description="姓名")
    avatar: Optional[str] = Field(None, description="头像URL")
    email: Optional[str] = Field(None, description="邮箱")
    phone: Optional[str] = Field(None, description="手机号")
    status: Optional[int] = Field(1, description="状态：1启用，0禁用")
    department: Optional[str] = Field(None, description="部门")
    person_id: Optional[int] = Field(None, description="人员ID")
    roles: Optional[List[int]] = Field(None, description="角色ID列表")


class UserCreateDB(BaseModel):
    """用于持久化到数据库的创建模型（不包含 roles 等非 ORM 字段）。"""
    username: str = Field(..., description="用户名")
    password: str = Field(..., description="密码（已哈希）")
    name: Optional[str] = Field(None, description="姓名")
    avatar: Optional[str] = Field(None, description="头像URL")
    email: Optional[str] = Field(None, description="邮箱")
    phone: Optional[str] = Field(None, description="手机号")
    status: Optional[int] = Field(1, description="状态：1启用，0禁用")
    department: Optional[str] = Field(None, description="部门")
    person_id: Optional[int] = Field(None, description="人员ID")


class UserUpdate(BaseModel):
    username: Optional[str] = Field(None, description="用户名（如允许修改需唯一）")
    name: Optional[str] = Field(None, description="姓名")
    avatar: Optional[str] = Field(None, description="头像URL")
    email: Optional[str] = Field(None, description="邮箱")
    phone: Optional[str] = Field(None, description="手机号")
    status: Optional[int] = Field(None, description="状态：1启用，0禁用")
    department: Optional[str] = Field(None, description="部门")
    person_id: Optional[int] = Field(None, description="人员ID")
    roles: Optional[List[int]] = Field(None, description="角色ID列表")


class PasswordChangeRequest(BaseModel):
    old_password: str = Field(..., description="旧密码")
    new_password: str = Field(..., description="新密码")


class UserUpdateDB(BaseModel):
    """用于持久化到数据库的更新模型（不包含 roles 等非 ORM 字段）。"""
    username: Optional[str] = Field(None, description="用户名（如允许修改需唯一）")
    name: Optional[str] = Field(None, description="姓名")
    avatar: Optional[str] = Field(None, description="头像URL")
    email: Optional[str] = Field(None, description="邮箱")
    phone: Optional[str] = Field(None, description="手机号")
    status: Optional[int] = Field(None, description="状态：1启用，0禁用")
    department: Optional[str] = Field(None, description="部门")
    person_id: Optional[int] = Field(None, description="人员ID")